layui.use(['layer','form','table','element','layedit','upload','laydate'],function () {
    var layer = layui.layer
        ,form = layui.form
        ,table =layui.table
        ,element = layui.element
        ,layedit = layui.layedit
        ,laydate  = layui.laydate
        ,upload = layui.upload;


    laydate.render({
        elem: '#driverTime' //指定元素
    });


    form.on('select(roleChange)', function(data){
        var type = data.value;
        if(type == "1"){
            //说明是司机显示驾龄等信息
            $("#driverNoDiv").css("display","block");
            $("#drvierAgeDiv").css("display","block");
            $("#driverTimeDiv").css("display","block");
        }else{
            $("#driverNoDiv").css("display","none");
            $("#drvierAgeDiv").css("display","none");
            $("#driverTimeDiv").css("display","none");
        }
    });

//提交表单
form.on('submit(form)',function (data) {

    var data = {
        "userName":$("#userName").val(),
        "trueName":$("#trueName").val(),
        "idCard":$("#idCard").val(),
        "password":$("#password").val(),
        "phone":$("#phone").val(),
        "type":$("#type").val(),
        "driverNo":$("#driverNo").val(),
        "drvierAge":$("#drvierAge").val(),
        "showDriverTime":$("#driverTime").val(),
    };

    //保存项目
    $.ajax({
        url:"/admin/driver/save",
        type:"POST",
        data:data,
        success:function (result) {
            // console.log("data=="+form_data)
            if(result.flag){
                layer.msg(result.message);
                //清空内容
                // $("#form").reset();
                document.getElementById("form").reset();
                layui.form.render();
            }else{
                layer.msg(result.message);
            }
        },
        error:function () {
            layer.msg("系统错误！");
        }
    });


});

});